//
//  BKXVisitorView.swift
//  微博
//
//  Created by 田凯 on 16/4/17.
//  Copyright © 2016年 田凯. All rights reserved.
//

import UIKit
import SnapKit
class BKXVisitorView: UIView {

    //定义一个 闭包 按钮的点击事件
    var callbag: (() -> ())?
    override init(frame: CGRect) {
        super.init(frame: frame)
        //设置 子空件
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //外界调用 方法 显示什么内容
    func setVisitorInfo(imageName: String?, titLe: String?){
    
        if let imag = imageName , tit = titLe{
        houseImageView.image = UIImage(named: imag)
            messageLabel.text = tit
            circleImageView.hidden = true
        
        }else{
        
        setCirleAnim()
        }
    
    }
    
    
    //圆圈 转起 方法
    func setCirleAnim(){
    //定义一个 基本动画
        let  anim = CABasicAnimation(keyPath: "transform.rotation")
        anim.duration = 10
        anim.repeatCount = MAXFLOAT
        anim.toValue = M_PI * 2
        anim.removedOnCompletion = false
        circleImageView.layer.addAnimation(anim, forKey: nil)
    
    }
    
    
    
    // MARK: - 设置子控件
    func setupUI(){
    self.backgroundColor = RGB(red: 237, green: 237, blue: 237)
    
        // 添加子控件
        addSubview(circleImageView)
        addSubview(maskImageView)
        addSubview(houseImageView)
        addSubview(messageLabel)
        addSubview(registButton)
        addSubview(LoginButton)
        //添加约束
        circleImageView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(self)
        }
        maskImageView.snp_makeConstraints { (make) -> Void in
//            make.centerX.equalTo(self)
//            make.centerY.equalTo(self)
            make.center.equalTo(self)

        }
        
        houseImageView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(self)

        }
        messageLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(maskImageView.snp_bottom).offset(16)
            make.centerX.equalTo(maskImageView)
            make.height.equalTo(36)
            make.width.equalTo(230)
        }
        registButton.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(messageLabel)
            make.top.equalTo(messageLabel.snp_bottom).offset(16)
            make.size.equalTo(CGSize(width: 100, height: 36))
        }
        LoginButton.snp_makeConstraints { (make) -> Void in
            make.trailing.equalTo(messageLabel)
            make.top.equalTo(messageLabel.snp_bottom).offset(16)
            make.size.equalTo(CGSize(width: 100, height: 36))
        }

        
    }

    // MARK: - 懒加载控件
    // 圆圈
    private lazy var circleImageView: UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_smallicon"))
    //遮盖
    private lazy var maskImageView: UIImageView = {
        let maskImag = UIImageView(image: UIImage(named: "visitordiscover_feed_mask_smallicon"))
        return maskImag
        
        }()
    //小房子
    private lazy var houseImageView: UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_house"))
    

//文字lable
private lazy var messageLabel:UILabel = {
    
    let lab = UILabel(textcolor: UIColor.grayColor(), textFont: 14)
    
//    let lab = UILabel()
//    lab.textColor = UIColor.grayColor()
    // 设置换行
    lab.numberOfLines = 0
    // 对齐方式
    lab.textAlignment = .Center
//    lab.font = UIFont.systemFontOfSize(14)
    lab.text = "关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜"
    return lab
    }()
    //注册按钮
private lazy var registButton: UIButton = {
    let button = UIButton()
    // 添加按钮的点击事件
    button.addTarget(self, action: "login", forControlEvents: UIControlEvents.TouchUpInside)
    
    //设置背景图片
    button.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
    //设置titl
    button.setTitle("注册", forState: UIControlState.Normal)
    //设置 tit颜色

    button.setTitleColor(ThemeColor, forState: UIControlState.Normal)
    //设置字体颜色/ 大小
    button.titleLabel?.font = UIFont.systemFontOfSize(14)
    
    return button
    }()
    //登陆按钮
    private lazy var LoginButton: UIButton = {
        let button = UIButton()
         button.addTarget(self, action: "login", forControlEvents: UIControlEvents.TouchUpInside)
        //设置背景图片
        button.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        //设置titl
        button.setTitle("登陆", forState: UIControlState.Normal)
        //设置 tit颜色
        
        button.setTitleColor(ThemeColor, forState: UIControlState.Normal)
        //设置字体颜色/ 大小
        button.titleLabel?.font = UIFont.systemFontOfSize(14)
        
        return button
        }()
    // MARK: - 按钮的点击事件
    func login(){
        
            callbag?()
    
    }





}




